package com.wumeng.interview.view;

import androidx.appcompat.app.AppCompatActivity;
import androidx.coordinatorlayout.widget.CoordinatorLayout;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;

import com.google.android.material.snackbar.BaseTransientBottomBar;
import com.google.android.material.snackbar.Snackbar;
import com.wumeng.interview.R;

/**
  * @Time : 2021/8/2
  * @Author : Wu-Meng
  * @Description :
 */
public class SnackBarActivity extends AppCompatActivity {

    private CoordinatorLayout coordinatorLayout;

    private Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_snack_bar);
        initView();
        initClick();
    }

    /**
     * 初始化View
     */
    private void initView() {
        coordinatorLayout = findViewById(R.id.cl_root);
        btn = findViewById(R.id.show_snackBar_btn);
    }

    /**
     * 点击事件
     */
    private void initClick() {
        // 点击事件
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showSnackBar();
            }
        });

    }

    /**
     * 显示SnackBar
     */
    private void showSnackBar() {
        Snackbar.make(coordinatorLayout,"data Deleted", Snackbar.LENGTH_LONG)
                .setAction("Undo", new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {

                    }
                })
                .addCallback(new Snackbar.Callback(){
                    @Override
                    public void onShown(Snackbar sb) {
                        super.onShown(sb);
                    }

                    @Override
                    public void onDismissed(Snackbar transientBottomBar, int event) {
                        super.onDismissed(transientBottomBar, event);
                    }
                })
                .setAnimationMode(BaseTransientBottomBar.ANIMATION_MODE_SLIDE)
                .show();
    }

}